#!/usr/bin/env bash
# echo and eval
a=
while getopts a OPT; do
  case "$OPT" in
    a)
      # Append to file instead of overwriting.
      a=-a
      ;;
    ?)
      exit 2
      ;;
  esac
done
shift "$(($OPTIND - 1))"
cmd="$1"
outfile="${2:-/dev/null}"
echo "$cmd" | tee $a "$outfile"
eval "$cmd"
exit "$?"
